	<%@ page pageEncoding="utf-8"%>
<%
String parid=request.getParameter("parid");if(parid==null)parid="";
%>
<!DOCTYPE html>
<HTML>
  <head>
	<%@ include file="/platform/style.jsp"%>
	<script>
	$(function(){
		$("#tree").tree({
			url: ctx+"/com/frame/metadata/wordbook/WorkbookPage@loadCatalogs.page?id=<%=parid%>",
			onClick: function(node){
				},
			onSelect:function(node){
				$getByName("catalogId").val(node.id);
				showList(ctx+"/com/frame/metadata/wordbook/WorkbookPage@queryWrorkbook.page?id="+node.id);
			},
			onContextMenu: function(e,node){
				e.preventDefault();
				$getByName("catalogId").val(node.id);
				$('#mm').menu('show',{
					left: e.pageX,
					top: e.pageY
				});
			}
		})
	})
	function addCatalog(){
		var str=ctx+"/com/frame/metadata/wordbook/WorkbookPage@addShow.page?id="+$getByName("catalogId").val();
		window.parent.$w.openDialog({title:'新增目录',w:390,h:250,url:str,afterClose:function(re){
			if(re){
				var node=$('#tree').tree("find",$getByName("catalogId").val());
				var data=re.bean;
				if($getByName("catalogId").val()==''){
					node=$('#tree').tree("getRoot");
					$('#tree').tree("append",{
						data:[{id:data.id,text:data.name}]
					});
				}else{
					$('#tree').tree("append",{
						parent: node.target,
						data:[{id:data.id,text:data.name}]
					});
					$('#tree').tree("expand",node.target);
				}
			}
		}});
	}
	function editCatalog(){
		if($getByName("catalogId").val()!=''){
			var str=ctx+"/com/frame/metadata/wordbook/WorkbookPage@updateShow.page?id="+$getByName("catalogId").val();
			window.parent.$w.openDialog({title:'修改目录',w:390,h:250,url:str,afterClose:function(re){
				if(re){
					var node=$('#tree').tree("find",$getByName("catalogId").val());
					$('#tree').tree("update",{target:node.target,text:re.bean.name});
				}
			}})
		}
	}
	function delCatalog(){
		if($getByName("catalogId").val()!=''){
			window.parent.$w.confirmMsg('确定删除？',function(r){
				if(r){
					$w.doUrl(ctx+"/com/frame/metadata/wordbook/WorkbookPage@del.page?id="+$getByName("catalogId").val(),{},function(re){
						if(re.state=='ok'){
							var node=$('#tree').tree("find",$getByName("catalogId").val());
							$('#tree').tree("remove",node.target);
							$getByName("catalogId").val("");
						}
					});
				}
			})
		}
	}
	function showList(url){
		$("#mlayout").layout("panel","center").panel("refresh",url);
	}
	function addbook(){
		var str=ctx+"/com/frame/metadata/wordbook/WorkbookPage@showWrorkbook.page?new_=true&id="+$getByName("id").val();
			window.parent.$w.openDialog({title:'添加字典编码',w:460,h:300,url:str,afterClose:function(re){
			if(re){
				$w.execForm({form:$('#bookForm')})
			}
		}})
	}
	function editbook(id){
		var str=ctx+"/com/frame/metadata/wordbook/WorkbookPage@showWrorkbook.page?new_=false&id="+id;
			window.parent.$w.openDialog({title:'修改字典编码',w:460,h:300,url:str,afterClose:function(re){
			if(re){
				$w.execForm({form:$('#bookForm')})
			}
		}})
	}
	function delbook(id){
		window.parent.$w.confirmMsg('确定删除？',function(r){
			if(r){
				$w.doUrl(ctx+"/com/frame/metadata/wordbook/WorkbookPage@delWrorkbook.page?id="+id,{},function(){$w.execForm({form:$('#bookForm')})});
			}
		})
	}
	
	function showItemlist(code){
		$("#booklayout").layout("panel","center").panel("refresh",ctx+"/com/frame/metadata/wordbook/WorkbookPage@queryItem.page?bean.code="+code);
		window.setTimeout(function(){
			$("#itemtree").tree({
				url: ctx+"/com/frame/metadata/wordbook/WorkbookPage@loadItemTree.page?bean.code="+code,
				onSelect:function(node){
					$getByName("itemId").val(node.id);
				},
				onContextMenu: function(e,node){
					e.preventDefault();
					$getByName("itemId").val(node.id);
				}
			})
		},800);
	}
	
	function addItem(){
		var str=ctx+"/com/frame/metadata/wordbook/WorkbookPage@showItem.page?new_=true&bean.code="+$getByName("bean.code").val()+"&id="+$getByName("itemId").val();
			window.parent.$w.openDialog({title:'添加字典选项值',w:460,h:300,url:str,afterClose:function(re){
			if(re){
				var node=$('#itemtree').tree("find",$getByName("itemId").val());
				var datab=re.bean;
				if($getByName("itemId").val()==''){
					node=$('#itemtree').tree("getRoot");
					$('#itemtree').tree("append",{
						data:[{id:datab.id,text:datab.item_name}]
					});
				}else{
					$('#itemtree').tree("append",{
						parent: node.target,
						data:[{id:datab.id,text:datab.item_name}]
					});
					$('#itemtree').tree("expand",node.target);
				}
			}
		}})
	}
	function editItem(){
		if($getByName("itemId").val()!=""){
			var str=ctx+"/com/frame/metadata/wordbook/WorkbookPage@showItem.page?new_=false&id="+$getByName("itemId").val();
				window.parent.$w.openDialog({title:'编辑字典选项值',w:460,h:300,url:str,afterClose:function(re){
				if(re){
						var node=$('#itemtree').tree("find",$getByName("itemId").val());
						$('#itemtree').tree("update",{target:node.target,text:re.bean.item_name});
				}
			}})
		}
	}
	function delItem(){
		window.parent.$w.confirmMsg('确定删除？',function(r){
			if(r){
				$w.doUrl(ctx+"/com/frame/metadata/wordbook/WorkbookPage@delItem.page?id="+$getByName("itemId").val(),{},function(re){
					if(re.state=='ok'){
							var node=$('#itemtree').tree("find",$getByName("itemId").val());
							$('#itemtree').tree("remove",node.target);
							$getByName("itemId").val("");
					}
				});
			}
		})
	}
	
	function sortItem(){
		var str=ctx+"/com/frame/metadata/wordbook/WorkbookPage@sortItemShow.page?bean.code="+$getByName("bean.code").val()+"&id="+$getByName("itemId").val();
			window.parent.$w.openDialog({title:'字典选项排序',w:300,h:330,url:str,afterClose:function(re){
			if(re){
				$('#itemtree').tree("reload");
			}
		}})
	}
	</script>
  </head>
<body class="easyui-layout" id="mlayout">
<div data-options="region:'west',split:true" title="数据字典目录" style="width:200px">
	<input name="catalogId" type="hidden">
	<w:equal value="true" bind="edit">
		<div class="easyui-panel ui-toolBar" border="false" data-options="doSize:false">
			<a href="javascript:;" class="easyui-linkbutton" title="新增子机构" iconCls="icon_add" plain="true" onclick="addCatalog()">添加</a>
			<a href="javascript:;" class="easyui-linkbutton" title="修改已选机构" iconCls="icon_edit" plain="true" onclick="editCatalog()">修改</a>
			<a href="javascript:;" class="easyui-linkbutton" title="删除已选机构" iconCls="icon_del" plain="true" onclick="delCatalog()">删除</a>
		</div>
	</w:equal>
	<div class="easyui-tree" id="tree">
	</div>
</div>
<div data-options="region:'center',border:false,href:'<%=path %>/com/frame/metadata/wordbook/WorkbookPage@queryWrorkbook.page?id=<%=parid%>'">

</div>
<div id="mm"class="easyui-menu" style="width:90px;">
 <div onclick="addCatalog()" data-options="iconCls:'icon_add_m'">新增子目录</div>
 <div onclick="editCatalog()" data-options="iconCls:'icon_edit_m'">修改本目录</div>
 <div onclick="delCatalog()" data-options="iconCls:'icon_del_m'">删除本目录</div>
</div>
  </body>
</html>